home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Screenblankers / GBlanker / GSource / cxhand.c < prev    next >
C/C++ Source or Header  |  1996-09-26  |  5KB  |  206 lines

  1. /*
  2.  *  Copyright (c) 1994 Michael D. Bayne.
  3.  *  All rights reserved.
  4.  *
  5.  *  Please see the documentation accompanying the distribution for distribution
  6.  *  and disclaimer information.
  7.  */
  8.  
  9. #include <exec/memory.h>
  10. #include <libraries/commodities.h>
  11. #include <devices/inputevent.h>
  12.  
  13. #include "includes.h"
  14. #include "libraries.h"
  15. #include "protos/protos.h"
  16.  
  17. BlankMsg *InterruptMsg;
  18. struct MsgPort *CxPort;
  19. CxObj *ServerBroker;
  20. LONG timeCount = 0;
  21.  
  22. VOID __interrupt __saveds CxBFunc( CxMsg *CxMessage, CxObj *CxObject )
  23. {
  24.     struct InputEvent *Event = ( struct InputEvent * )CxMsgData( CxMessage );
  25.     
  26.     switch( Event->ie_Class )
  27.     {
  28.     case IECLASS_TIMER:
  29.         if( ++timeCount >=
  30.            ( Blanking ? Prefs->bp_RandTimeout : Prefs->bp_Timeout ))
  31.         {
  32.             InterruptMsg->bm_Flags = BF_INTERNAL;
  33.             InterruptMsg->bm_Type = BM_SENDBLANK;
  34.             PutMsg( ServerPort, ( struct Message * )InterruptMsg );
  35.             timeCount = 0;
  36.         }
  37.         return;
  38.     case IECLASS_RAWMOUSE:
  39.         if(( Event->ie_Code == IECODE_NOBUTTON )&&
  40.            ( Event->ie_Qualifier & IEQUALIFIER_RELATIVEMOUSE )&&
  41.            ( Prefs->bp_BlankCorner || Prefs->bp_DontCorner ))
  42.         {
  43.             Signal( ServerTask, SIGBREAKF_CTRL_D );
  44.         }
  45.         break;
  46.     case IECLASS_RAWKEY:
  47.         if( Event->ie_Code & IECODE_UP_PREFIX )
  48.             return;
  49.     }
  50.  
  51.     if( Blanking )
  52.     {
  53.         Blanking = FALSE;
  54.         InterruptMsg->bm_Flags = BF_INTERNAL;
  55.         InterruptMsg->bm_Type = BM_SENDUNBLANK;
  56.         PutMsg( ServerPort, ( struct Message * )InterruptMsg );
  57.     }
  58.     timeCount = 0;
  59. }
  60.  
  61. LONG HandleCxMess( VOID )
  62. {
  63.     LONG msgid, msgtype;
  64.     CxMsg *msg;
  65.     
  66.     while( msg = ( CxMsg * )GetMsg( CxPort ))
  67.     {
  68.         msgid = CxMsgID( msg );
  69.         msgtype = CxMsgType( msg );
  70.         ReplyMsg(( struct Message * )msg );
  71.         
  72.         switch( msgtype )
  73.         {
  74.         case CXM_IEVENT:
  75.             switch( msgid )
  76.             {
  77.             case EVT_CX_POPUP:
  78.                 OpenInterface();
  79.                 break;
  80.             case EVT_CX_BLANK:
  81.                 InterruptMsg->bm_Flags = BF_INTERNAL;
  82.                 InterruptMsg->bm_Type = BM_SENDBLANK;
  83.                 PutMsg( ServerPort, ( struct Message * )InterruptMsg );
  84.                 break;
  85.             }
  86.             break;
  87.         case CXM_COMMAND:
  88.             switch( msgid )
  89.             {
  90.             case CXCMD_DISABLE:
  91.                 ActivateCxObj( ServerBroker, 0l );
  92.                 break;
  93.             case CXCMD_ENABLE:
  94.                 ActivateCxObj( ServerBroker, 1l );
  95.                 break;
  96.             case CXCMD_KILL:
  97.                 return QUIT;
  98.             case CXCMD_APPEAR:
  99.             case CXCMD_UNIQUE:
  100.                 OpenInterface();
  101.                 break;
  102.             case CXCMD_DISAPPEAR:
  103.                 CloseInterface();
  104.                 break;
  105.             default:
  106.                 break;
  107.             }
  108.         default:
  109.             break;
  110.         }
  111.     }
  112.  
  113.     return OK;
  114. }
  115.  
  116. VOID ShutdownCX( VOID )
  117. {
  118.     CxMsg *msg;
  119.     
  120.     if( InterruptMsg )
  121.         FreeVec( InterruptMsg );
  122.  
  123.     if( CxPort )
  124.     {
  125.         if( ServerBroker )
  126.             DeleteCxObjAll( ServerBroker );
  127.         ServerBroker = 0L;
  128.         
  129.         while( msg = ( CxMsg * )GetMsg( CxPort ))
  130.             ReplyMsg(( struct Message * )msg );
  131.         DeletePort( CxPort );
  132.         CxPort = 0L;
  133.     }
  134. }
  135.  
  136. CxObj *GarshneBroker( LONG Pri, struct MsgPort *Port, LONG *cxError )
  137. {
  138.     struct NewBroker Broker;
  139.  
  140.     Broker.nb_Version = NB_VERSION;
  141.     Broker.nb_Name = "Garshneblanker";
  142.     Broker.nb_Title = VERS;
  143.     Broker.nb_Descr = "Groovy modular screen blanker";
  144.     Broker.nb_Unique = NBU_UNIQUE|NBU_NOTIFY;
  145.     Broker.nb_Flags = COF_SHOW_HIDE;
  146.     Broker.nb_Pri = Pri;
  147.     Broker.nb_Port = Port;
  148.     
  149.     return CxBroker( &Broker, cxError );
  150. }
  151.     
  152. LONG SetupCX( VOID )
  153. {
  154.     InterruptMsg = AllocVec( sizeof( BlankMsg ), MEMF_CLEAR|MEMF_PUBLIC );
  155.     if( !InterruptMsg )
  156.         return QUIT;
  157.     
  158.     InterruptMsg->bm_Mess.mn_ReplyPort = ServerPort;
  159.     InterruptMsg->bm_Mess.mn_Length = sizeof( BlankMsg );
  160.         
  161.     if( CxPort = CreatePort( 0L, 0L ))
  162.     {
  163.         LONG cxError = 0L;
  164.     
  165.         ServerBroker = GarshneBroker( Prefs->bp_Priority, CxPort, &cxError );
  166.  
  167.         if( cxError == CBERR_OK )
  168.         {
  169.             CxObj *pHotKey, *bHotKey;
  170.             
  171.             ActivateCxObj( ServerBroker, 0l );
  172.  
  173.             pHotKey = CxFilter( Prefs->bp_PopKey );
  174.             AttachCxObj( pHotKey, CxSender( CxPort, EVT_CX_POPUP ));
  175.             AttachCxObj( pHotKey, CxTranslate( 0L ));
  176.             AttachCxObj( ServerBroker, pHotKey );
  177.             
  178.             bHotKey = CxFilter( Prefs->bp_BlankKey );
  179.             AttachCxObj( bHotKey, CxSender( CxPort, EVT_CX_BLANK ));
  180.             AttachCxObj( bHotKey, CxTranslate( 0L ));
  181.             AttachCxObj( ServerBroker, bHotKey );
  182.             
  183.             AttachCxObj( ServerBroker, CxCustom( CxBFunc, 0L ));
  184.  
  185.             if( !CxObjError( ServerBroker ))
  186.             {
  187.                 ActivateCxObj( ServerBroker, 1l );
  188.                 return OK;
  189.             }
  190.         }
  191.     }
  192.     ShutdownCX();
  193.  
  194.     return QUIT;
  195. }
  196.  
  197. LONG CheckCX( VOID )
  198. {
  199.     LONG cxError = 0L;
  200.     
  201.     ServerBroker = GarshneBroker( 0L, 0L, &cxError );
  202.     DeleteCxObj( ServerBroker );
  203.  
  204.     return ( cxError == CBERR_OK ) ? OK : QUIT;
  205. }
  206.